package ch.evaleto.gwt.media.client.player.util;

import java.io.IOException;

import ch.evaleto.gwt.media.client.player.Playlist;
import ch.evaleto.gwt.media.client.player.medias.Podcast;
import ch.evaleto.gwt.media.client.player.medias.Radio;
import ch.evaleto.gwt.media.client.player.medias.Sound;
import ch.evaleto.gwt.media.client.player.medias.Video;

import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONException;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;

public class JSONReader {
	public native void setField(Object o,String clazz, String field, String value)/*-{
    	o.@clazz::field = value;
	}*/;
	public native void setFieldNull(Object o,String clazz, String field)/*-{
		o.@clazz::field = null;
	}*/;
	
	public void setField(Object map, String field, JSONValue value) throws JSONMappingException{
		try{
        	System.out.println(map.getClass().getName());
	        if (value.isArray()!=null){
	        }else
	        if(value.isBoolean()!=null){
	        	setField(map,map.getClass().getName(),field,value.isBoolean().toString());
	        }else
	        if(value.isNull()!=null){
	        	setFieldNull(map,map.getClass().getName(),field);
	        }else
	        if(value.isNumber()!=null){
	        	setField(map,map.getClass().getName(),field,value.isNumber().toString());
	        }else
	        if(value.isString()!=null){
	        	setField(map,map.getClass().getName(),field,value.isString().stringValue());
	        }else{
	        	throw new JSONMappingException("");
	        }
		} catch (Exception e) {
			e.printStackTrace();
        	throw new JSONMappingException(e.getMessage());
		}
	}
	public JSONReader(Object map, String content) {
	            JSONValue root = JSONParser.parse(content);
	            
	}
}
